<?php
namespace app\crm\model;
use think\Db;
use think\Model;
use think\Cache;
use think\Loader;


class Upload extends Model
{
    /**
     * 获取系统参数列表
     * @return array <日报列表信息>
     */
    public function uploadPictureData()
    {
        $page = $_REQUEST["page"]; // 页码
        $limit = $_REQUEST["limit"]; // 每页显示条数
        $count = Db::name('sys_picture')->count();
        // 查询状态为1的用户数据 并且每页显示10条数据
        $pictureDataList = Db::name('sys_picture')->limit(($page-1)*$limit,$limit)->order('createtime DESC')->select();
        foreach ($pictureDataList as &$val) {
            $val['display'] = $val['display'] == 'Y'? '是': '否';
        }
        $rowsList = count($pictureDataList) ? $pictureDataList : false;
        $arrData["code"] = 0;
        $arrData["msg"] = '';
        $arrData["count"] = $count;
        $arrData["data"] = $rowsList;
        return $arrData;
    }


    public function insertPicture ($data)
    {
        $result = Db::name('sys_picture')->insert($data);
        if ($result) {
            echo json_encode(array('success'=>true,'msg'=>'保存成功！'));
        } else {
            echo json_encode(array('msg'=>'保存失败！'));
        }
    }


    public function getPictureInfo ($id) 
    {
        $pictureInfo = Db::name('sys_picture')->where('id="'.$id.'"')->find();
        return $pictureInfo;
    }



    public function updatePicture ($data)
    {
        $result = Db::name('sys_picture')->update($data);
        if ($result) {
            echo json_encode(array('success'=>true,'msg'=>'编辑成功！'));
        } else {
            echo json_encode(array('msg'=>'编辑失败！'));
        }
    }


    public function delPicture ($id)
    {
        $result = Db::name('sys_picture')->delete($id);
        if ($result) {
            echo json_encode(array('success'=>true,'msg'=>'删除成功！'));
        } else {
            echo json_encode(array('msg'=>'删除失败！'));
        }
    }
}